package Exercise;

import java.util.Scanner;

/**
 * Description：
 * Author: zhangc
 * Date：2017/8/10 16:27
 */
public class AvgApple {


    public static int avgApple(int num, int[] arr) {
        if (num <= 0 || arr == null || arr.length <= 0)
            return -1;
        int same = (arr[ 0 ] % 2 == 0 ? 0 : 1);
        for (int i = 1; i < arr.length; i++) {
            if (arr[ i ] % 2 == 1)
                same++;
        }
        if (same > 0 && same < num)
            return -1;
        int sum = arr[ 0 ];
        for (int i = 1; i < arr.length; i++) {
            sum += arr[ i ];
        }
        if (sum % num != 0)
            return -1;
        int avg = sum / num;
        int times = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[ i ] > avg)
                times += (arr[ i ] - avg) / 2;
        }
        return times;
    }

//    public static void main(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        int num = scanner.nextInt();
//        int[] arr = new int[ num ];
//        for (int i = 0; i < num; i++) {
//            arr[ i ] = scanner.nextInt();
//        }
//        System.out.println(avgApple(num, arr));
//    }

    public static void main(String[] args) {
        int[] arr = {70, 41, 30, 20, 99, 70, 100, 44, 40, 72, 63, 92, 98, 94, 54, 92, 24, 69, 90, 58, 14, 96, 90, 98, 84, 98, 72, 96, 92, 87, 48, 74, 72, 66, 22, 14, 100, 48, 36, 54, 36, 89, 74, 100, 64, 50, 90, 82, 97, 91, 88, 98, 86, 92, 47, 90, 34, 82, 88, 94, 98, 84, 92, 50, 68, 80, 70, 85, 88};
        System.out.println(avgApple(69, arr));
    }


}
